﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneMake.Model
{
    //买家地域分析
    public class report_buyer_area_stat
    {
        [MapToField(FieldName = "省份")]
        public string province { get; set; }  //牌子

        [MapToField(FieldName = "成交金额")]
        public decimal amount { get; set; } //
    }

    public class report_buyer_area_stat2
    {
        [MapToField(FieldName = "省份")]
        public string province { get; set; }  //牌子

        [MapToField(FieldName = "占比")]
        public decimal per_amount { get; set; } //占比
    }

    partial class ReportHelper
    {
        //获取某品牌，某个月份，共34个地区
        public List<report_buyer_area_stat> get_report_buyer_area_stat(string Brand, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = "select province,sum(amount) as amount from mf_m_mjdyfx where brand=@0 and stat_datetime between @1 and @2 group by province";
            List<report_buyer_area_stat> reports = new List<report_buyer_area_stat>();
            foreach (report_buyer_area_stat item in db.Query<report_buyer_area_stat>(sql, Brand, beginTime.Date, endTime.Date))
                reports.Add(item);
            return reports;
        }


        //占比
        public List<report_buyer_area_stat2> get_report_buyer_area_stat2(string Brand, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = "select province,sum(per_amount) as per_amount from mf_m_mjdyfx where brand=@0 and stat_datetime between @1 and @2 group by province";
            List<report_buyer_area_stat2> reports = new List<report_buyer_area_stat2>();
            foreach (report_buyer_area_stat2 item in db.Query<report_buyer_area_stat2>(sql, Brand, beginTime.Date, endTime.Date))
                reports.Add(item);
            return reports;
        }
    }
}
